package com.ruoyi.match.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.EasyExcel;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.match.config.MyMapConvConvertStrategy;
import com.ruoyi.match.domain.ChNotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.match.domain.ChPosi;
import com.ruoyi.match.service.IChPosiService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 持仓信息Controller
 * 
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/posi")
public class ChPosiController extends BaseController
{
    @Autowired
    private IChPosiService chPosiService;


    @Autowired
    MyMapConvConvertStrategy myMapConvConvertStrategyl;


    /**
     * 查询持仓信息列表
     */
    @RequiresPermissions("match:posi:list")
    @GetMapping("/list")
    public TableDataInfo list(ChPosi chPosi)
    {
        startPage();
        Long userId = SecurityUtils.getUserId();
        List<ChPosi> list = chPosiService.selectChPosiLists(chPosi,userId);
        return getDataTable(list);
    }

    /**
     * 导出持仓信息列表
     */
    @RequiresPermissions("match:posi:export")
    @Log(title = "持仓信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChPosi chPosi) throws IOException {
        List<ChPosi> list = chPosiService.selectChPosiList(chPosi);
        EasyExcel.write(response.getOutputStream(),ChNotice.class)
                .registerConverter(myMapConvConvertStrategyl)
                .sheet("我的持仓数据")
                .doWrite(list);
    }

    /**
     * 获取持仓信息详细信息
     */
    @RequiresPermissions("match:posi:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(chPosiService.selectChPosiById(id));
    }

    /**
     * 新增持仓信息
     */
    @RequiresPermissions("match:posi:add")
    @Log(title = "持仓信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChPosi chPosi)
    {
        return toAjax(chPosiService.insertChPosi(chPosi));
    }

    /**
     * 修改持仓信息
     */
    @RequiresPermissions("match:posi:edit")
    @Log(title = "持仓信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChPosi chPosi)
    {
        return toAjax(chPosiService.updateChPosi(chPosi));
    }

    /**
     * 删除持仓信息
     */
    @RequiresPermissions("match:posi:remove")
    @Log(title = "持仓信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chPosiService.deleteChPosiByIds(ids));
    }
}
